package xhwl.insurance.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import xhwl.insurance.R;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.ProcessWithDrawShowActivity;
import xhwl.insurance.http.api.WithDrawApplyApi;
import xhwl.insurance.http.bean.resp.WithDrawApplyResp;
import xhwl.insurance.util.DimenUtil;
import xhwl.insurance.util.ImmerseUtil;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;

public class WithDrawApplyActivity extends BaseActivity implements View.OnClickListener {

    private TextView total_yj;
    private TextView text_withdraw;
    private LinearLayout back_click;
    private TextView title_textview;
    private TextView total_money_heart;
    private TextView total_money_lung;
    private TextView total_money_liver;
    private TextView total_money_eye;
    private TextView total_money_female;
    private RelativeLayout rlTop;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_with_draw_apply);
    }

    @Override
    public void initViews() {
        back_click = (LinearLayout) findViewById(R.id.back_click);
        title_textview = (TextView) findViewById(R.id.title_textview);
        total_yj = (TextView) findViewById(R.id.total_yj);
        text_withdraw = (TextView) findViewById(R.id.text_withdraw);
        total_money_heart = (TextView) findViewById(R.id.total_money_heart);
        total_money_lung = (TextView) findViewById(R.id.total_money_lung);
        total_money_liver = (TextView) findViewById(R.id.total_money_liver);
        total_money_eye = (TextView) findViewById(R.id.total_money_eye);
        total_money_female = (TextView) findViewById(R.id.total_money_female);
        title_textview.setText("申请提现");
        rlTop= (RelativeLayout) findViewById(R.id.top_layout);

        immerseUtil=new ImmerseUtil(this);
        immerseUtil.setImmerseLayout(rlTop);
    }

    @Override
    protected void processOper() {
        super.processOper();
    }

    @Override
    public void initListener() {
        text_withdraw.setOnClickListener(this);
        back_click.setOnClickListener(this);
    }

    @Override
    public void loadData() {
        requestData();
    }

    private void requestData() {
        WithDrawApplyApi api = new WithDrawApplyApi();
        HttpManager.getInstance().dealHttp(this, api, new OnNextListener<WithDrawApplyResp>() {
            @Override
            public void onNext(WithDrawApplyResp resp) {
                String eye_money = "";
                String heart_money = "";
                String lung_money = "";
                String female_money = "";
                if (null != resp.getEye_money()) {
                    eye_money = resp.getEye_money();
                } else {
                    eye_money = "0";
                }
                if (null != resp.getHeart_money()) {
                    heart_money = resp.getHeart_money();
                } else {
                    heart_money = "0";
                }
                if (null != resp.getTum_money()) {
                    lung_money = resp.getTum_money();
                } else {
                    lung_money = "0";
                }
                if (null != resp.getGyn_money()) {
                    female_money = resp.getGyn_money();
                } else {
                    female_money = "0";
                }
                double totalMoney = Double.parseDouble(eye_money) + Double.parseDouble(heart_money) + Double.parseDouble(lung_money) + Double.parseDouble(female_money);
                total_money_eye.setText(DimenUtil.addComma(DimenUtil.getsDotTwoNum(eye_money)));
                total_money_heart.setText(DimenUtil.addComma(DimenUtil.getsDotTwoNum(heart_money)));
                total_money_liver.setText("0.00");
                total_money_lung.setText(DimenUtil.addComma(DimenUtil.getsDotTwoNum(lung_money)));
                total_money_female.setText(DimenUtil.addComma(DimenUtil.getsDotTwoNum(female_money)));
                total_yj.setText(DimenUtil.addComma(DimenUtil.getsDotTwoNum(String.valueOf(totalMoney))));
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_click:
                this.finish();
                break;
            case R.id.text_withdraw:
                startActivity(new Intent(this, ProcessWithDrawShowActivity.class));
//                AppUtil.startWebViewActivity(this, "http://wx-heartorg.yk2020.com/weixin/index.php?m=Expert&c=Loverank&a=take", "申请提现");
                break;
        }
    }

}
